package com.example.springioc1.Controller;

import com.example.springioc1.component.UserComponent;
import com.example.springioc1.service.UserSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller//Bean
public class HelloController {
   // @Autowired
    private UserSevice sevice;
    private UserComponent component;

    //构造方法注入
    //如果构造函数有无参的，默认是使用无参的，如果要使用某个，需要加上Autowired
//    public HelloController() {
//    }
//
//    public HelloController(UserSevice sevice) {
//        this.sevice = sevice;
//    }
//    @Autowired
//    public HelloController(UserSevice sevice, UserComponent component) {
//        this.sevice = sevice;
//        this.component = component;
//    }

    @Autowired
    public void setSevice(UserSevice sevice) {
        this.sevice = sevice;
    }
    @Autowired
    public void setComponent(UserComponent component) {
        this.component = component;
    }


    public void sayHi(){
        component.doComponent();
        sevice.doSevice();
        System.out.println("hi,HelloController");
    }
}
